package com.px.service;

import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.springframework.stereotype.Service;

@Service
public class CardServiceImpl implements CardService {
    /**
     * 身份证查询
     *
     * @param name
     * @param idCard
     * @return
     * @throws Exception
     */
    @Override
    public String verity(String name, String idCard) throws Exception {
        //创建客户端对象用于发送http请求    用于发送请求的http对象
        OkHttpClient okHttpClient = new OkHttpClient.Builder().build();
        //创建表单体对象用于保存请求的参数
        FormBody.Builder formbody = new FormBody.Builder();
        //设置请求体的参数
        formbody.add("name",name);
        formbody.add("idcard",idCard);
        //创建具体的参数体对象
        FormBody build = formbody.build();
        //设置调用地址
        String url = "http://eid.shumaidata.com/eid/check";
        Request request = new Request.Builder().url(url).
                addHeader("Authorization","APPCODE 7ce0f88f2b8b49769ea0a04424eaf747").
                post(build).build();
        //发送请求并获取返回结果
        Response response = okHttpClient.newCall(request).execute();
        String result = response.body().string();
        return result;
    }
}
